package com.sqx.modules.agentCityDetails.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.sqx.modules.agentCityDetails.entity.AgentCityDetails;
import com.sqx.modules.agentCityDetails.dao.AgentCityDetailsDao;
import com.sqx.modules.agentCityDetails.service.AgentCityDetailsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import com.sqx.common.utils.Result;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.factory.annotation.Autowired;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import java.time.LocalDateTime;

/**
 * 代理钱包明细 服务实现类
 * @author wuChang
 * @since 2024-03-22
 */
@Service
public class AgentCityDetailsServiceImp extends ServiceImpl<AgentCityDetailsDao, AgentCityDetails> implements AgentCityDetailsService {


    @Override
    public Result saveAgentCityDetails(AgentCityDetails agentCityDetails) {
        if (agentCityDetails.getDetailsId() != null) {
            return Result.upStatus(baseMapper.updateById(agentCityDetails));
        } else {
            agentCityDetails.setCreateTime(LocalDateTime.now());
            return Result.upStatus(baseMapper.insert(agentCityDetails));
        }
    }

    @Override
    public IPage<AgentCityDetails> getAgentCityDetailsList(Integer page, Integer limit, AgentCityDetails agentCityDetails) {
        Page<AgentCityDetails> pages;
        if (page != null && limit != null) {
            pages = new Page<>(page, limit);
        } else {
            pages = new Page<>();
            pages.setSize(-1);
        }
        return baseMapper.selectPage(pages, new QueryWrapper<>(agentCityDetails).orderByDesc("create_time"));
    }
}
